package com.itemstodisplay {
	import com.greensock.TweenMax;

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.AntiAliasType;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	public class ItemsToDisplay extends Sprite {
		private var _myFormat : TextFormat;
		private var _txtField : TextField;
		private var _myFont : Font;
		private	var _labels : Array = new Array("1", "3", "5");
		private	var	_numItemButtons : int = _labels.length;
		private var _button : ItemDisplayItem;
		private var _currentNav : Sprite;

		public function ItemsToDisplay() {
			createCells();
			mainTextField();
		}

		private function createCells() : void {
			var btnNum : int = 3;
			var spacing : Number = 0;
			var itemToDisplayContainer : Sprite = new Sprite();
			addChild(itemToDisplayContainer);

			for (var i : int = 0 ; i < btnNum ;i++) {
				_button = new ItemDisplayItem(_labels[i]);
				_button.x = i * (_button.width + spacing);
				_button.y = 23;
				_button.buttonMode = true;
				_button.mouseChildren = false;
				_button.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
				_button.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
				_button.addEventListener(MouseEvent.CLICK, buttonClick);
				addChild(_button);
			}
		}

		private function mainTextField() : void {
			_myFont = new Font1();

			_myFormat = new TextFormat();
			_myFormat.font = _myFont.fontName;
			_myFormat.size = 15;
			_myFormat.letterSpacing = 1;
			_myFormat.align = TextFormatAlign.LEFT;

			_txtField = new TextField();
			_txtField.x = 0;
			_txtField.y = 0;
			_txtField.width = 120;
			_txtField.height = 20;
			_txtField.selectable = false;
			_txtField.textColor = 0x000000;
			_txtField.border = false;
			_txtField.defaultTextFormat = _myFormat;
			_txtField.embedFonts = true;
			_txtField.antiAliasType = AntiAliasType.NORMAL;
			_txtField.text = "items to display";
			addChild(_txtField);
		}

		public function buttonOver(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (navItem != _currentNav) {
				TweenMax.to(e.target, .5, {tint:0x787879});
			}
		}

		public function buttonOut(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (navItem != _currentNav) {
				TweenMax.to(e.target, .2, {tint:null});
				// _button.deselect();
			}
		}

		public function buttonClick(e : MouseEvent) : void {
			var navItem : Sprite = e.target as Sprite;
			if (_currentNav != null) {
				TweenMax.to(_currentNav, .3, {tint:null});
			}
			TweenMax.to(e.target, .3, {tint:0x000000});
			_currentNav = navItem;
			// _button.select();
		}
	}
}
